package o;

import android.content.Context;
import android.database.SQLException;
import android.text.TextUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class clf {
    private static List<cfr> ˊ = new ArrayList();
    private static List<String> ˎ = new ArrayList();
    private final cli ॱ;

    public static int ˊ() {
        return 1;
    }

    public static void ॱ(cfr o_cfr) {
        ˊ.add(o_cfr);
    }

    public clf(cli o_cli, Context context) {
        this.ॱ = o_cli;
    }

    public void ˋ() throws ArrayIndexOutOfBoundsException, SQLException {
        cle.ˎ.ˎ("GameResourceDbUpdateHelper", "GameResourceDbUpdateHelper initTables begin ");
        ˏ();
        ˎ();
        cle.ˎ.ˎ("GameResourceDbUpdateHelper", "GameResourceDbUpdateHelper initTables end ");
    }

    private void ˎ() {
        for (String str : ˎ) {
            if (TextUtils.isEmpty(str)) {
                cle.ˎ.ˊ("GameResourceDbUpdateHelper", "error tableName");
            } else {
                cle.ˎ.ˋ("GameResourceDbUpdateHelper", " deleteUnusedTables tableName=" + str);
                if (this.ॱ.ˏ(str)) {
                    this.ॱ.ˎ(str);
                }
            }
        }
    }

    private void ˏ() throws SQLException {
        for (cfr o_cfr : ˊ) {
            String t_ = o_cfr.t_();
            if (this.ॱ.ˏ(t_)) {
                this.ॱ.ˊ(t_);
                cle.ˎ.ˎ("GameResourceDbUpdateHelper", "GameResourceDbUpdateHelpertableName exist moidfy table " + t_ + " successfully.");
                try {
                    this.ॱ.ॱ(o_cfr.K_());
                    ˋ(t_);
                    cle.ˎ.ˋ("GameResourceDbUpdateHelper", "GameResourceDbUpdateHelper insert data to table " + t_ + " successfully.");
                    this.ॱ.ˋ(t_);
                    cle.ˎ.ˋ("GameResourceDbUpdateHelper", "GameResourceDbUpdateHelperdrop table _temp_" + t_ + " successfully.");
                } catch (SQLException e) {
                    cle.ˎ.ˊ("GameResourceDbUpdateHelper", "initTablesEx SQLException");
                    throw new SQLException("initTablesEx SQLException");
                }
            }
            cle.ˎ.ˎ("GameResourceDbUpdateHelper", "GameResourceDbUpdateHelper create table " + t_);
            try {
                this.ॱ.ॱ(o_cfr.K_());
            } catch (SQLException e2) {
                cle.ˎ.ˊ("GameResourceDbUpdateHelper", "initTablesEx SQLException");
                throw new SQLException("initTablesEx SQLException");
            }
        }
    }

    private void ˋ(String str) throws SQLException {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(" INSERT INTO ");
        stringBuilder.append(str);
        stringBuilder.append(" SELECT ");
        try {
            try {
                String ˏ = ˏ(this.ॱ.ᐝ(str), this.ॱ.ᐝ("_temp_" + str));
                if (ˏ != null) {
                    stringBuilder.append(ˏ);
                    stringBuilder.append(" FROM ");
                    stringBuilder.append("_temp_" + str);
                    try {
                        this.ॱ.ॱ(stringBuilder.toString());
                        return;
                    } catch (SQLException e) {
                        throw new SQLException("GameResourceDbUpdateHelper insertData mDbHelper.executeSQL error");
                    }
                }
                throw new NullPointerException("GameResourceDbUpdateHelper insertData stringInsertColumns is null. [tableName=" + str + "]");
            } catch (SQLException e2) {
                throw new SQLException("GameResourceDbUpdateHelper insertData mDbHelper.getColumnNames error ");
            }
        } catch (SQLException e3) {
            throw new SQLException("insertData SQLException:" + e3.getMessage());
        }
    }

    private String ˏ(String[] strArr, String[] strArr2) {
        StringBuilder stringBuilder = new StringBuilder();
        ArrayList arrayList = new ArrayList();
        if (strArr2 != null) {
            List asList = Arrays.asList(strArr2);
        } else {
            Object obj = arrayList;
        }
        if (strArr == null || strArr.length <= 0 || strArr2 == null) {
            return null;
        }
        for (int i = 0; i < strArr.length; i++) {
            String str = strArr[i];
            if (asList.contains(str)) {
                stringBuilder.append(str);
            } else {
                stringBuilder.append("\"\"");
            }
            if (i != strArr.length - 1) {
                stringBuilder.append(',');
            }
        }
        return stringBuilder.toString();
    }
}
